import {
    validEmpty,
    validPhone,
    validPassword,
    validEmail,
} from "./validate.js";

export const val_phone = (rule, value, callback) => {
    if (validEmpty(value)) {
        callback(new Error("请输入手机号"));
    } else if (validPhone(value)) {
        callback(new Error("手机号输入有误"));
    } else {
        callback();
    }
};

export const val_shortCode = (rule, value, callback) => {
    if (validEmpty(value)) {
        callback(new Error("请输入验证码"));
    } else {
        callback();
    }
};

export const val_passwrod = (rule, value, callback) => {
    if (validEmpty(value)) {
        callback(new Error("请输入密码"));
    } else if (validPassword(value)) {
        callback(new Error("密码为8位以上大小写字母和数字组成"));
    } else {
        callback();
    }
};

export const val_email = (rule, value, callback) => {
    if (validEmpty(value)) {
        callback(new Error("请输入邮箱"));
    } else if (validEmail(value)) {
        callback(new Error("邮箱地址不合法"));
    } else {
        callback();
    }
};
